package com.hurl.stock.util;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.hibernate.cfg.reveng.DelegatingReverseEngineeringStrategy;
import org.hibernate.cfg.reveng.ReverseEngineeringStrategy;
import org.hibernate.cfg.reveng.TableIdentifier;

public class HibernateReverseEngineeringStrategy extends DelegatingReverseEngineeringStrategy{

	private static final Log log = LogFactory.getLog(HibernateReverseEngineeringStrategy.class);
	
	@Override
	public String tableToClassName(TableIdentifier tableIdentifier) {
		
		String tableName = tableIdentifier.getName().toLowerCase();
		log.debug("=============tableToClassName=============");
		log.debug("table name: "+tableName);
		String[] arr = tableName.split("_");
		String className="com.hurl.stock.persistence.";
		for(int i=0;i<arr.length;i++){
			if(i>0 || !arr[i].equals("t")){
				if(arr[i].length()==1){
					className+=arr[i].toUpperCase();
				}else{
					className+=arr[i].substring(0,1).toUpperCase()+arr[i].substring(1);
				}
			}
		}
		className+="BO";
		log.debug("className: "+className);
		return className;
	}

	public HibernateReverseEngineeringStrategy(
			ReverseEngineeringStrategy delegate) {
		super(delegate);
	}
}
